Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid wrong infinite loop #269

Merged
merged 1 commit into from
Aug 27, 2024
Merged

Avoid wrong infinite loop #269

merged 1 commit into from
Aug 27, 2024

Conversation

mame
Copy link
Member

@mame mame commented Aug 27, 2024

TypeProf caused an infinite loop under the following situation:

@a = @b[0]
@b = '/' + @a
  1. both @A and @b is untyped
  2. @b is changed to a String because of the second line (String#+)
  3. @A is changed to a String? because of the first line (String#[])
  4. @b is changed to nil because String#+ does not accept String?
  5. go to 2

This change fixes the loop by making String#+ to accept String?.

TODO: it should emit a warning, but it is a bot complex considering the situation where passing Integer | String | nil to the following foo:

def foo: (Integer) -> Integer
       | (String) -> String
``

TypeProf caused an infinite loop under the following situation:

```
@A = @b[0]
@b = '/' + @A
```

1. both @A and @b is untyped
2. @b is changed to a String because of the second line (String#+)
3. @A is changed to a String? because of the first line (String#[])
4. @b is changed to nil because String#+ does not accept String?
5. go to 2

This change fixes the loop by making `String#+` to accept `String?`.

TODO: it should emit a warning, but it is a bot complex considering the
situation where passing `Integer | String | nil` to the following foo:

```
def foo: (Integer) -> Integer
       | (String) -> String
``
@mame mame enabled auto-merge (rebase) August 27, 2024 07:46
@mame mame merged commit 86ca835 into ruby:master Aug 27, 2024
6 checks passed
@mame mame deleted the avoid-infinite-loop branch August 27, 2024 07:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant